﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace idataplatform
{
    public partial class nfglcounting : Form
    {
        public nfglcounting()
        {
            InitializeComponent();
        }

        private void nfglcounting_Load(object sender, EventArgs e)
        {
            conncls conns = new conncls();
            string fgledateSQL = "SELECT DATE_FORMAT(MAX(xftime),'%Y年%c月%d日') FROM xfjd_ipark;";
            dateTimePicker1.Text = conns.varStr(fgledateSQL);

            label4.Text = "会员复购率=一年内有过2次及以上消费的会员人数/一年内有过消费的会员总人数";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conncls conns = new conncls();
            string fgnoSQL = "SELECT COUNT(CISHU) FROM (SELECT COUNT(HYNO) AS CISHU FROM xfjd_ipark WHERE xftime>= DATE_ADD('" + dateTimePicker1.Value.ToShortDateString() + "',interval -365 day) AND xftime<= '" + dateTimePicker1.Value.AddDays(1).ToShortDateString() + "' GROUP BY HYNO,phoneno HAVING CISHU > 1) A;";
            string xfnoSQL = "SELECT COUNT(DISTINCT HYNO) FROM xfjd_ipark WHERE xftime>= DATE_ADD('" + dateTimePicker1.Value.ToShortDateString() + "',interval -365 day) AND xftime<= '" + dateTimePicker1.Value.AddDays(1).ToShortDateString() + "';";
            //MessageBox.Show(fgnoSQL);
            
            int fgno = conns.varInt(fgnoSQL);
            int xfno = conns.varInt(xfnoSQL);
            textBox1.Text = Math.Round((Convert.ToDouble(fgno) / Convert.ToDouble(xfno)), 4).ToString("0.00%");
            textBox2.Text = fgno.ToString();
            textBox3.Text = xfno.ToString();
        }
    }
}
